package com.arpa.wms.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 接口文档 Swagger配置
 * @author LEO
 */
@Configuration
@EnableSwagger2
@EnableWebMvc
@Profile({"dev","leo", "test","prd"})
public class Swagger2 {


    @Value("${swagger.show}")
    private boolean swaggerShow;



    @Bean(name = "WMS2-API")
    public Docket wmsApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .enable(swaggerShow).apiInfo(apiInfo("WMS2.0服务","WMS2.0服务接口","V1.0"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.arpa.wms"))
                .paths(PathSelectors.any())
                .build().groupName("WMS2-API");
    }

    @Bean(name = "OMS2-API")
    public Docket omsApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .enable(swaggerShow).apiInfo(apiInfo("OMS2.0服务","OMS2.0服务接口","V1.0"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.arpa.oms"))
                .paths(PathSelectors.any())
                .build().groupName("OMS2-API");
    }



    /**
     * api信息
     *
     * @param name        标题
     * @param description 描述
     * @param version     版本
     * @return
     */
    private ApiInfo apiInfo(String name, String description, String version) {
        return new ApiInfoBuilder().title(name).description(description).version(version).build();
    }
}
